How to create X and Y axis flip animation using HTML and CSS ? 您所在的位置:网站首页 book page flip animation css code with demo How to create X and Y axis flip animation using HTML and CSS ?

How to create X and Y axis flip animation using HTML and CSS ?

2023-03-09 06:21| 来源: 网络整理| 查看: 265

The flip animation is the kind of loading animation in which we use a square flip effect to give the feel of loading animation. These kinds of animations are useful in times when the content of the website is taking too long to load. This animation can keep visitors engage and prevent them from leaving your web page without seeing the content. The main concept behind working of this animation is the application of transform and @keyframes. Please go through them before you try to execute this code.

HTML Code:: Create a HTML file and create a div in it.

              X and Y axis flip animation              GeeksforGeeks         X and Y axis flip animation              

CSS Code: In CSS, the first thing that we have done is provide a background to the body. Apply background to the div and some border-radius to have a rounded corner. Apply linear animation with identifier named as animate. Using key-frames we will apply animation to our identifier. We are rotating are square along X-axis during the first half frames and along Y-axis during rest. This is not required but you can change the angles of rotation to have a different kind of flip effect. This one is the basic flip effect.

    body {        margin: 0;        padding: 0;    }      h1 {        color: green;    }      .geeks {        position: absolute;        top: 45%;        left: 50%;        transform: translate(-50%, -50%);        width: 100px;        height: 100px;        background: green;        border-radius: 13px;        animation: animate 2s linear infinite;    }      @keyframes animate {        0% {            transform: translate(-50%, -50%)                        perspective(200px)                        rotateX(0deg)                        rotateY(0deg);        }          50% {            transform: translate(-50%, -50%)                        perspective(200px)                        rotateX(-180deg)                        rotateY(0deg);        }          100% {            transform: translate(-50%, -50%)                        perspective(200px)                        rotateX(-180deg)                        rotateY(-180deg);        }    }

Final solution: It is the combination of HTML and CSS codes.

              X and Y axis flip animation            body {            margin: 0;            padding: 0;        }                  h1 {            color: green;        }        .geeks {            position: absolute;            top: 45%;            left: 50%;            transform: translate(-50%, -50%);            width: 100px;            height: 100px;            background: green;            border-radius: 13px;            animation: animate 2s linear infinite;        }                  @keyframes animate {            0% {                transform: translate(-50%, -50%)                   perspective(200px)                   rotateX(0deg)                   rotateY(0deg);            }            50% {                transform: translate(-50%, -50%)                  perspective(200px)                   rotateX(-180deg)                   rotateY(0deg);            }            100% {                transform: translate(-50%, -50%)                  perspective(200px)                   rotateX(-180deg)                  rotateY(-180deg);            }        }                  GeeksforGeeks         X and Y axis flip animation              

Output:

My Personal Notes arrow_drop_up


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有